# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @File  : 工具创建-返回工具执行的工件.py
# @Author: dongguangwen
# @Date  : 2025-03-23 22:07
import random
from typing import List, Tuple

from langchain_core.tools import tool


@tool(response_format="content_and_artifact")
def generate_random_ints(min: int, max: int, size: int) -> Tuple[str, List[int]]:
    """Generate size random ints in the range [min, max]."""
    array = [random.randint(min, max) for _ in range(size)]
    content = f"Successfully generated array of {size} random ints in [{min}, {max}]."
    return content, array


ret = generate_random_ints.invoke({"min": 0, "max": 9, "size": 10})
print(ret)

ret2 = generate_random_ints.invoke(
    {
        "name": "generate_random_ints",
        "args": {"min": 0, "max": 9, "size": 10},
        "id": "123",  # required
        "type": "tool_call",  # required
    }
)
print(ret2)

"""
Successfully generated array of 10 random ints in [0, 9].
content='Successfully generated array of 10 random ints in [0, 9].' name='generate_random_ints' tool_call_id='123' artifact=[3, 1, 8, 9, 1, 7, 9, 0, 0, 6]
"""